#include "header.h"

int draw_rect_grid(int sideLengthx, int sideLengthy, int squareSizex, int squareSizey, int x, int y, int color) {
  if (((sideLengthx * squareSizex) >= SCREEN_W) || ((sideLengthy * squareSizey) >= SCREEN_H)) return -1;
  if (sideLengthx <= 0 || sideLengthy <= 0 || squareSizex <= 0 || squareSizey <= 0) return -1;
  int i;
  int sidepixX = sideLengthx * squareSizex, sidepixY = sideLengthy * squareSizey;
  int voff = y - (sidepixY/2), vdyn = voff;
  int hoff = x - (sidepixX/2), hdyn = hoff;
  for (i = 0; i <= sideLengthy; i++) 
  {
    hline(buffer, hoff, vdyn, (hoff + sidepixX), color);
    vdyn += squareSizey;
  }
  for (i = 0; i <= sideLengthx; i++) 
  {
    vline(buffer, hdyn, voff, (voff + sidepixY), color);
    hdyn += squareSizex;
  }
  return 0;
}

int draw_square_grid(int sidelength, int squaresize, int x, int y, int color) 
{
  return draw_rect_grid(sidelength, sidelength, squaresize, squaresize, x, y, color);
}

void draw_image(BITMAP *image, int x, int y) 
{
  blit(image, buffer, 0, 0, (x - image->w/2), (y - image->h/2), image->w, image->h);
}
